package com.fanfanwang.ffw.app.ui.login;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.toolbox.NetworkImageView;
import com.fanfanwang.ffw.app.AppManager;
import com.fanfanwang.ffw.app.asynctask.GetParknumListAsyncTask;
import com.fanfanwang.ffw.app.asynctask.TenantLoginAsyncTask;
import com.fanfanwang.ffw.app.base.BaseActivity;
import com.fanfanwang.ffw.app.common.StringUtils;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.tenant.R;
import com.fanfanwang.ffw.app.ui.HomeActivity;
import com.fanfanwang.ffw.app.widget.CommonTitleBar;

/** 登录 */
public class LoginAct extends BaseActivity {

	private CommonTitleBar commonTitleBar;
	private EditText lo_mobile;
	private EditText lo_password;
	private TextView tv_forgetpassword;
	private TextView tv_reg_account;
	private Button lo_btn_complete;
	private String mobile = "";
	private String password = "";
	private Activity mAct;
	private Intent mIntent;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initView();
		AppManager.getAppManager().addActivity(this);
		initData();
		setListener();
	}

	@Override
	public void initView() {
		// TODO Auto-generated method stub
		setContentView(R.layout.activity_login);
		mAct = this;
		commonTitleBar = (CommonTitleBar) findViewById(R.id.common_titlebar);
		lo_btn_complete = (Button) findViewById(R.id.lo_btn_complete);
		lo_mobile = (EditText) findViewById(R.id.lo_mobile);
		lo_password = (EditText) findViewById(R.id.lo_password);
		tv_forgetpassword = (TextView) findViewById(R.id.tv_forgetpassword);
		tv_reg_account=(TextView)findViewById(R.id.tv_reg_account);
	}

	@Override
	public void setListener() {
		// TODO Auto-generated method stub
		lo_btn_complete.setOnClickListener(new OnClickListener() {

			@SuppressLint("NewApi")
			@Override
			public void onClick(View v) {
				mobile = lo_mobile.getText().toString();
				password = lo_password.getText().toString();
				// TODO Auto-generated method stub
				if (mobile.isEmpty()) {
					ToastAlone.showToast(LoginAct.this,
							getString(R.string.login_error_tel),
							Toast.LENGTH_SHORT);
				}else if(TextUtils.isEmpty(password)){
					ToastAlone.showToast(LoginAct.this,
							getString(R.string.login_error_pwd),
							Toast.LENGTH_SHORT);
				} else {
					// 验证登录信息
					new TenantLoginAsyncTask(mAct,mobile,password).execute("");
				
//					mIntent = new Intent(mAct, HomeActivity.class);
//					startActivity(mIntent);
				}
			}
		});
		tv_reg_account.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mIntent = new Intent(mAct, RegisterAct.class);
				startActivity(mIntent);
			}
		});
		tv_forgetpassword.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mIntent = new Intent(mAct, FindPwdAct.class);
				startActivity(mIntent);
			}
		});


	}

	@Override
	public void initData() {
		// TODO Auto-generated method stub
		commonTitleBar.setCenterText(getString(R.string.login));
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			// do something...
			// mIntent = new Intent(mAct, GuideAct.class);
			// startActivity(mIntent);
			// finish();
		}
		return super.onKeyDown(keyCode, event);
	}

}
